import sys

import requests

from api.Base import Login


class merProductList(Login):
    # 查询
    def product_list(self, keyword):
        data = {
            'url': '/api/admin/merchant/product/list',
            'method': 'get',
            'headers': {'Authori-zation': self._mer_token},
            'params': {
                'page': '1',
                'limit': '20',
                'cateId': '873',
                'keywords': keyword,
                'type': '1',
                'isPaidMember': 'false',
                'productType': '0',
                'temp': '1726641848',
            }
        }
        return self.mer_send_request(sys._getframe().f_code.co_name,data)

    # 保存
    def merchant_product_save(self, name, price=100, stock=99999):
        data = {
            'url': '/api/admin/merchant/product/save',
            'method': 'post',
            'headers': {'Authori-zation': self._mer_token},
            'json': {
                'image': 'https://crmebjavamer.oss-cn-beijing.aliyuncs.com/crmebimage/public/store/2024/08/09/329e096ada794a27993d7c1a9b3e6dfe1izzcb4g22.png',
                'sliderImages': [
                    'https://crmebjavamer.oss-cn-beijing.aliyuncs.com/crmebimage/public/store/2024/08/09/329e096ada794a27993d7c1a9b3e6dfe1izzcb4g22.png',
                ],
                'sliderImage': '["https://crmebjavamer.oss-cn-beijing.aliyuncs.com/crmebimage/public/store/2024/08/09/329e096ada794a27993d7c1a9b3e6dfe1izzcb4g22.png"]',
                'name': name,
                'intro': '啊大大',
                'keyword': '阿达',
                'cateIds': [
                    859,
                    873,
                ],
                'cateId': '859,873',
                'unitName': '111',
                'sort': 1,
                'isShow': False,
                'tempId': 285,
                'attrValue': [
                    {
                        'image': 'https://crmebjavamer.oss-cn-beijing.aliyuncs.com/crmebimage/public/store/2024/08/09/329e096ada794a27993d7c1a9b3e6dfe1izzcb4g22.png',
                        'price': price,
                        'vipPrice': 0.01,
                        'cost': 100,
                        'otPrice': 999,
                        'stock': stock,
                        'barCode': '',
                        'weight': 2,
                        'volume': 0.01,
                        'brokerage': 0,
                        'brokerageTwo': 0,
                        'cdkeyId': None,
                        'cdkeyLibraryName': '',
                        'expand': '',
                        'attrValue': '{"规格":"默认"}',
                        'productId': 0,
                    },
                ],
                'attr': [
                    {
                        'attrName': '规格',
                        'attrValues': '默认',
                        'id': 0,
                    },
                ],
                'selectRule': '',
                'isSub': False,
                'isPaidMember': False,
                'content': '',
                'specType': False,
                'couponIds': [],
                'coupons': [],
                'categoryId': 3,
                'guaranteeIds': '6',
                'guaranteeIdsList': [
                    6,
                ],
                'brandId': 0,
                'type': 0,
                'isAutoSubmitAudit': False,
                'isAutoUp': False,
            }
        }
        return self.mer_send_request(sys._getframe().f_code.co_name,data)

    # 下架
    def product_down(self, pid):
        data = {
            'url': f'/api/admin/merchant/product/down/{pid}',
            'method': 'post',
            'headers': {'Authori-zation': self._mer_token},
        }
        return self.mer_send_request(sys._getframe().f_code.co_name,data)

    # 上架
    def product_up(self, pid):
        data = {
            'url': f'/api/admin/merchant/product/up/{pid}',
            'method': 'post',
            'headers': {'Authori-zation': 'self._mer_token'},
        }
        return self.mer_send_request(sys._getframe().f_code.co_name,data)

    # 删除放入回收站  type为"delete" 删除  为recycle 放入回收站
    def product_delete(self, pid, type='recycle'):
        data = {
            'url': '/api/admin/merchant/product/delete',
            'method': 'post',
            'headers': {'Authori-zation': self._mer_token},
            'json': {
                'id': pid,
                'type': type,
            }
        }
        return self.mer_send_request(sys._getframe().f_code.co_name,data)

    # 批量放入回收站
    def product_batch_recycle(self, ids):
        data = {
            'url': '/api/admin/merchant/product/batch/recycle',
            'method': 'post',
            'headers': {'Authori-zation': self._mer_token},
            'json': {
                'idList': ids,
            }
        }
        return self.mer_send_request(sys._getframe().f_code.co_name,data)

    # 批量删除
    def product_batch_delete(self, ids):
        data = {
            'url': '/api/admin/merchant/product/batch/delete',
            'method': 'post',
            'headers': {'Authori-zation': self._mer_token},
            'json': {
                'idList': ids
            }
        }
        return self.mer_send_request(sys._getframe().f_code.co_name,data)


if __name__ == '__main__':
    print(merProductList().product_list('黄梅'))
